package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Dept;
import com.qk.entity.Role;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @LogAnno
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        roleService.deleteById(id);
        return Result.success();
    }
    @LogAnno
    @PutMapping
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        Role role =roleService.getById(id);
        return Result.success(role);
    }
    @GetMapping
    public Result Page(@RequestParam(name = "name",required = false)String name,
                       @RequestParam(name = "label",required = false)Integer label,
                       @RequestParam(name = "page",defaultValue = "1") Integer page,
                       @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        PageResult<Role> pageResult =roleService.page(name,label,page,pageSize);
        return Result.success(pageResult);
    }
    @LogAnno
    @PostMapping
    public Result add(@RequestBody Role role){
        roleService.add(role);
        return Result.success();
    }
    @GetMapping("/list")
    public Result getAllRoles() {
        List<Role> roles = roleService.getAllRoles();
        return Result.success(roles);
    }
}
